<template>
	<view class="content" style="height: 100%;">
		<view class="mainpadding" style="height: 100%;">
			<view class="flexleft" style="align-items: flex-start;height: 100%;">
				<scroll-view scroll-y="true" style="height: 100%;width: 35%;">
					<view class="margin_right" style="">
						
						<view class="mainpaddingpos ffffff radius">
							<view class="flexbetween pdl">
								<view class="titletext bold hei_text">{{goodsInfo.name}}</view>
								<!-- <view class="main_size bold color_red">${{djprice}}</view> -->
							</view>
							<view class="pdl ffffff margin_top" v-if="goodsInfo.goods_sale.length">
								<view class="flexbetween">
									<view class="titletext bold hei_text">處置選擇</view>
									<view class="listbtnhuang " v-if="goodsInfo.is_cl==1" @click="clshow=true">處理選擇</view>
								</view>
								<view class="margin_top">
									<u-radio-group v-model="is_df" placement="row" circle>
										<u-radio activeColor="#ff8505" :customStyle="{marginRight: '30rpx'}"
											:label="'【'+item.name+'】'" :name="index"
											v-for="(item,index) in goodsInfo.goods_sale" :key="item.id"></u-radio>
									</u-radio-group>
								</view>
							</view>
							<view class="flexbetween margin_top" v-if="goodsInfo.is_size==1">
								<view class="flexleft" v-if="goodsInfo.shopformula.type!=2">
									<view class="main_size color_red" style="font-size: 26rpx;">寬({{goodsInfo.shopformula.size}})</view>
									<view class="bghui bghuider radius margin_left2" style="padding: 10rpx 10rpx;">
										<input type="number"
											style="text-align: center;min-width: 130rpx;max-width: 130rpx;"
											placeholder="請輸入" class="xiaohong" v-model="wei" @blur="weiBlur">
									</view>
								</view>
								<view class="flexleft " v-if="goodsInfo.shopformula.type!=1">
									<view class="main_size color_red" style="font-size: 26rpx;">高({{goodsInfo.shopformula.size}})</view>
									<view class="bghui bghuider radius margin_left2" style="padding: 10rpx 10rpx;">
										<input type="number"
											style="text-align: center; min-width: 130rpx;max-width: 130rpx;"
											placeholder="請輸入" class="xiaohong" :disabled="heiDisabled" v-model="hei"
											@blur="heiBlur">
									</view>
								</view>
							</view>
							<view class="flexbetween bghui radius mainpaddingpos margin_top">
								<view class="flexleft" style="font-size: 24rpx;">
									<view class="hei_text  bold">單位：</view>
									<view class="color_red  bold"
										v-text="formulaValue+(goodsInfo.unit==null? '': goodsInfo.unit)"></view>
								</view>
								<view class="flexleft" style="font-size: 24rpx;">
									<view class="hei_text  bold">單價：</view>
									<view class="color_red  bold">${{djprice}}</view>
								</view>
							</view>
							<view class="flexbetween  bghui radius mainpaddingpos margin_top1"  style="font-size: 24rpx;">
								<view class="hei_text  bold" v-if="goodsInfo.is_cl==1 && clxzj_value">用量：<text
										class="xiaohong">{{clxzj_value}}{{goodsInfo.jj_unit}}</text></view>
								<view class="hei_text  bold" v-if="!clxzj_value"></view>
								<view class="hei_text bold" >小計價格：<text class="xiaohong" style="font-size: 24rpx;"
										v-text="'$'+subTotal"></text>
								</view>
							</view>
						</view>
						<view class="flexbetween ffffff mainpadding2 radius">
							<view class="titletext bold hei_text">數量</view>
							<view class="numberBg" v-if="goodsInfo.is_cl!=1">
								<u-number-box button-size="36" color="#000000" bgColor="#F7F7F7" iconStyle="color: #fff"
									v-model="num"></u-number-box>
							</view>
							<view class="titletext bold hei_text" v-if="goodsInfo.is_cl==1">{{num}}</view>
						</view>
					</view>
				</scroll-view>
				<scroll-view scroll-y="true" style="height: 100%;width: 45%;">
					<view class="margin_right">
						<view class="mainpadding_top ffffff radius" style="padding-top: 0;"
							v-if="goodsInfo.goods_sku.length">
							<!-- <view class="titletext bold hei_text">商品規格一</view> -->
							<view class="flexleft flex_wrap">
								<view class="margin_top margin_right guigelable radius"
									v-for="item in goodsInfo.goods_sku" :key="item.id" @click="goSelectGoods(item)">
									{{item.name}}
								</view>
							</view>
						</view>
						<view class=" ffffff margin_top1 radius" v-for="(item,index) in spuList" :key="item.id">
							<view class="flexbetween mainpaddingpos" style="background-color: #f8b62a;font-size: 20rpx;">
								<view class=" hei_text bold">{{item.name}}</view>
								<view class="hei_text  bold" v-if="item.num_b!=0">
									{{item.fh==1?'':'至少'}}選擇{{item.num_b}}個
								</view>
							</view>
							<scroll-view scroll-x="true" style="width: 100%;">
								<view class="flexleft" style="align-items: flex-start;">
									<view class="margin_top1 margin_right1 flexcenter itembox"
										v-for="(value,i) in item.list" v-if="i%2==0" :key="value.id" @click="value.num=value.num+1">
										<view class="itemboxcenter">
											<view class="hei_text main_size bold" style="font-size: 28rpx;min-width: 80rpx;white-space: nowrap;">{{value.name}}</view>
											<view class="huang_text main_size bold">
												<text class="main_size color_red textcenter margin_right1" :style="{color:value.money==0?'#d3e3fd':'#ff0000'}" style="font-size: 24rpx;">+{{value.money}}</text>
											</view>
											<!-- <view class="margin_top1">
												<u-number-box button-size="36" color="#000000" :min="0" bgColor="#F7F7F7"
													iconStyle="color: #fff" v-model="value.num"></u-number-box>
											</view> -->
										</view>
									</view>
								</view>
								<view class="flexleft" style="align-items: flex-start;">
									<view class="margin_top1 margin_right1 flexcenter itembox"
										v-for="(value,i) in item.list"  v-if="i%2==1" :key="value.id" @click="value.num=value.num+1">
										<view class="itemboxcenter">
											<view class="hei_text main_size bold" style="font-size: 28rpx;min-width: 80rpx;white-space: nowrap;">{{value.name}}</view>
											<view class="huang_text main_size bold">
												<text class="main_size color_red textcenter margin_right1" :style="{color:value.money==0?'#d3e3fd':'#ff0000'}" style="font-size: 24rpx;">+{{value.money}}</text>
											</view>
											<!-- <view class="margin_top1">
												<u-number-box button-size="36" color="#000000" :min="0" bgColor="#F7F7F7"
													iconStyle="color: #fff" v-model="value.num"></u-number-box>
											</view> -->
										</view>
									</view>
								</view>
							</scroll-view>
						</view>
					</view>
				</scroll-view>
				<view class="" style="height: 100%;width: 20%;">
					<view class="flexcolumnbet" style="width: 100%;height: 100%;;">
						<scroll-view scroll-y="true" style="height: 85%;">
							<view>
								<view class="flexbetween margin_top1" style="width: 100%;" v-for="item in rightArr"
									:key="item.id">
									<view class="xiaohei flexleft main_size">
										<view class="xiankuan" style="max-width: 300rpx;width: auto;">{{item.name}}
										</view>
										<view class="">*{{item.num}}</view>
									</view>
									<view class="" @click="delrightarr(item.id)">
										<u-icon name="trash" color="#ff0000" size="18"></u-icon>
									</view>
								</view>
							</view>
						</scroll-view>
						<view class="flexbetween" style="width: 100%;">
							<view class="leftAllprice flexleft ffffff">
								<view class="huang_text" style="font-size: 40rpx;" v-text="'$'+money"></view>
							</view>
							<view class="rightsubmit flexcenter mainpadding" style="min-width: 130rpx;"
								@click="confirm">
								<view class="hei_text main_size">提交</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-modal :show="clshow" title="處理選擇" confirmText="確認" @confirm="chongzhi" cancelText="關閉" @cancel="clshow=false"
			:showConfirmButton="false">
			<view class="slot-content" style="width: 600rpx;">
				<scroll-view scroll-y="true" style="height: 300rpx;" v-if="goodsInfo.goods_sale.length">
					<view class="flexbetween margin_top" v-for="item in goodsInfo.goods_sale[this.is_df].sale_money"
						:key="item.id" @click="checkchuli(item)">
						<view class="hei_text main_size bold">用量：<text class="xiaohong"
								style="margin-right: 50rpx;">{{item.js_num}}{{goodsInfo.jj_unit}}</text>單價：<text
								class="xiaohong margin_right1">{{item.d_money}}元</text></view>
						<u-icon name="checkmark-circle-fill" color="#999" size="20" v-if="item.id!=clxz_id"></u-icon>
						<u-icon name="checkmark-circle-fill" color="#ffb800" size="20" v-if="item.id==clxz_id"></u-icon>
					</view>
				</scroll-view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	export default {
		name: "goodsmodal",
		props: ["goods_id"],
		data() {
			return {
				currentNum: 0,
				swiperList: [], //轮播图
				num: 1,
				is_df: 0,
				goodsInfo: {
					goods_sale: []
				},
				spuList: [], //商品规格二列表
				// weiDisabled: false,
				heiDisabled: true,

				shop_id: uni.getStorageSync("shop_id"),
				wei: "", //宽
				hei: "", //高
				spunatname: "", //规格2属性名称
				spunatid: "", //规格2属性id
				num: 1, //数量
				addimage: [], //上传的图片
				addimage_arr: [], //上传的图片展示
				formulaValue: 1, //公式算出来的值
				notes: "", //备注
				secondList: [], //二级商品列表
				pageShow: false,
				selectSpuNum: [], //商品规格2已選擇的规格属性数量
				djprice: 0,
				clxz_id: "", //处理選擇的id
				clxzj_value: "", //处理選擇的計算值
				//处理選擇
				clshow: false,
				sp_attr: [],
				posdc: 1, //是否为pos点餐？0否，1是
				rightArr: []
			}
		},
		watch: {
			spuList: {
				deep: true,
				handler(newval) {
					let arr = []
					newval.forEach(item => {
						item.list.forEach(ite => {
							if (ite.num > 0) {
								arr.push(ite)
							}
						})
					})
					this.rightArr = arr
				}
			},
			clxz_id: {
				handler(newval) {
					console.log("jinglke");
					if (this.clxz_id == "" && this.goodsInfo.is_cl == 1) {
						this.clshow = true
					}
				},
				deep: true
			},
			num: {
				handler(newVal) {
					// this.subTotal()
					if (this.goodsInfo.goods_sale.length && this.clxz_id == "") {
						let arr = []
						this.goodsInfo.goods_sale[this.is_df].sale_money.forEach(item => {
							if (Number(item.js_num) <= Number(this.formulaValue * this.num)) {
								arr.push(item.d_money)
							}
						})
						if (arr.length) {
							this.djprice = arr[0]
						} else {
							this.djprice = this.goodsInfo.goods_sale[this.is_df].sale_money[0].d_money
						}
					}
				},
				deep: true
			},
			is_df: {
				handler(newval) {
					console.log(1212);
					if (this.goodsInfo.is_cl == 0) {
						if (this.goodsInfo.goods_sale.length && this.clxz_id == "") {
							this.djprice = this.goodsInfo.goods_sale[this.is_df].sale_money[0].d_money
						}
					} else {
						this.clxz_id = ""
						this.clxzj_value = ""
					}
				},
				deep: true
			},
			formulaValue: {
				handler(newval) {
					console.log(newval, 12345);
					if (this.goodsInfo.goods_sale.length && this.clxz_id == "") {
						let arr = []
						this.goodsInfo.goods_sale[this.is_df].sale_money.forEach(item => {
							if (Number(item.js_num) <= Number(newval * this.num)) {
								arr.push(item.d_money)
							}
						})
						if (arr.length) {
							this.djprice = arr[0]
						} else {
							this.djprice = this.goodsInfo.goods_sale[this.is_df].sale_money[0].d_money
						}
					}
				},
				deep: true
			},
			wei(newVal) {
				if (newVal) {
					this.heiDisabled = false
				}
			},
		},
		computed: {
			subTotal() { //小計价格
				let end_price = 0
				let value = this.formulaValue * this.djprice * this.num
				console.log(value);
				let price_j = 0
				if (this.goodsInfo.goods_sale.length) {
					price_j = Number(this.goodsInfo.goods_sale[this.is_df].price_j)
				}
				if (value > price_j) {
					end_price = value
				} else {
					end_price = price_j
				}
				return Number(end_price).toFixed(0)
			},
			money() { //总价
				let price = 0
				this.spuList.forEach(item => {
					item.list.forEach(value => {
						// if (value.isChecked) {
						// 	price = Number(price) + Number(value.money)
						// }
						if (value.num) {
							price = Number(price) + Number(value.money) * value.num
						}
					})
				})
				price = (Number(this.subTotal) + price)
				return price
			}
		},
		created() {
			this.getInfo()
		},
		methods: {
			delrightarr(id){
				this.spuList.forEach(item => {
					item.list.forEach(ite => {
						if (ite.id==id) {
							ite.num = 0
						}
					})
				})
			},
			checkchuli(item) {
				this.clxz_id = item.id
				this.clxzj_value = item.js_num
				this.djprice = item.d_money
				this.clshow = false
			},
			async getInfo() { //商品详情
				let res = await this.http.request('/api/goods/deail', 'POST', {
					goods_id: this.goods_id
				})
				if (res.code == 1) {
					if (res.data.carouselimages) {
						res.data.carouselimages.split(",").forEach(item => {
							this.swiperList.push(this.imgUrlUser + item)
						})
					}
					let detailsImages_arr = []
					if (res.data.detailsimages) {
						res.data.detailsimages.split(",").forEach(item => {
							detailsImages_arr.push(this.imgUrlUser + item)
						})
					}
					this.$set(res.data, "detailsImages_arr", detailsImages_arr)
					let spuList = []
					res.data.goods_spu.forEach(item => {
						spuList.push({
							id: item.id,
							name: item.name,
							num_b: item.num_b,
							list: [],
							fh: item.fh
						})
					})
					res.data.goods_spunat.forEach(item => {
						item.image = this.imgUrlUser + item.image
						// this.$set(item, "isChecked", false)
						this.$set(item, "num", 0)
						spuList.forEach(value => {
							if (item.goods_spu_id == value.id) {
								value.list.push(item)
							}
						})
					})
					spuList.forEach(item => {
						this.selectSpuNum.push({
							id: item.id,
							selectId: []
						})
					})
					this.spuList = spuList
					console.log(this.spuList, "spuList")
					let sp_attr = []
					if (res.data.sp_attr) {
						res.data.sp_attr.split(",").forEach(item => {
							sp_attr.push({
								name: item,
								value: ""
							})
						})
					}
					this.sp_attr = sp_attr
					this.goodsInfo = res.data
					if (res.data.is_cl == 1) {
						this.clshow = true
					}
					// if (res.data.price) {//这里应该有问题，先注释了吧
					// 	this.djprice = res.data.goods_sale.length ? (res.data.goods_sale[0].sale_money.length ? res
					// 		.data.goods_sale[0].sale_money[0].d_money : res.data.price) : res.data.price
					// } else {
					// 	this.djprice = res.data.price
					// }
					this.djprice = res.data.goods_sale.length ? (res.data.goods_sale[0].sale_money.length ? res
						.data.goods_sale[0].sale_money[0].d_money : res.data.price) : res.data.price
					console.log(this.goodsInfo);
					this.pageShow = true
				} else if (res.code == 0) {} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			weiBlur() { //宽失去焦点
				let value = 0
				let weiValue = 0
				let heiValue = 0
				let info = this.goodsInfo.shopformula;
				let goodsInfo = this.goodsInfo;
				// if (!this.hei) {
				// 	return false
				// }
				if (info.type == 0) {
					weiValue = eval(this.wei + info.wei_a + info.wei_b)
					heiValue = eval(this.hei + info.hei_a + info.hei_b)
					if (goodsInfo.size) {
						let weinumshow = this.ifnumshow(weiValue, goodsInfo.size.split(";"))
						let heinumshow = this.ifnumshow(heiValue, goodsInfo.size.split(";"))
						if (weinumshow && heinumshow) { //如果两個都没有超过的话就正常判断
							if (Number(weiValue) > Number(heiValue)) {
								weiValue = this.MaxFn(weiValue, goodsInfo.size.split(";"))
							} else {
								heiValue = this.MaxFn(heiValue, goodsInfo.size.split(";"))
							}
						}
						if (weinumshow && !heinumshow) { //如果宽度没有超过高度超过了就計算宽度的值
							weiValue = this.MaxFn(weiValue, goodsInfo.size.split(";"))
							console.log(1);
						}
						if (!weinumshow && heinumshow) { //如果高度没有超过宽度超过了就計算高度的值
							heiValue = this.MaxFn(heiValue, goodsInfo.size.split(";"))
							console.log(2);
						}
					}
					value = eval((weiValue + info.wei_c + heiValue) + info.hei_c + info.numval)
				} else if (info.type == 1) {
					weiValue = eval(this.wei + info.wei_a + info.wei_b)
					value = eval(weiValue + info.hei_c + info.numval)
				} else if (info.type == 3) {
					value = Number(this.wei) > Number(this.hei) ? this.wei : this.hei
				} else if (info.type == 4) {
					value = Number(this.wei) > Number(this.hei) ? this.hei : this.wei
				} else if (info.type == 5) {
					weiValue = (Number(this.wei) / Number(info.wei_b)).toFixed(0) * Number(info.wei_b)
					heiValue = (Number(this.hei) / Number(info.hei_b)).toFixed(0) * Number(info.hei_b)
					value = eval(weiValue + info.wei_c + heiValue + info.hei_c + info.numval)
				}
				console.log(weiValue, "寬度", heiValue, "高度", value, "結果");
				// let pricetwo = value.toFixed(info.num)
				this.formulaValue = (Number(value).toFixed(info.num))>=1?Number(value).toFixed(info.num):1
			},
			ifnumshow(val, arr) {
				let num = 0
				arr.forEach(item => {
					if (Number(val) < Number(item)) {
						num = num + 1
					}
				})
				return num ? true : false
			},
			MaxFn(str, arr) {
				let list1 = []
				let returnnum = 0
				arr.forEach(item => {
					if (Number(str) < Number(item)) {
						list1.push(item)
					}
				})
				returnnum = (Math.min.apply(null, list1))
				return returnnum
			},
			heiBlur() { //高失去焦点
				let value = 0
				let weiValue = 0
				let heiValue = 0
				let info = this.goodsInfo.shopformula
				let goodsInfo = this.goodsInfo;
				if (info.type == 0) {
					weiValue = eval(this.wei + info.wei_a + info.wei_b)
					heiValue = eval(this.hei + info.hei_a + info.hei_b)
					if (goodsInfo.size) {
						let weinumshow = this.ifnumshow(weiValue, goodsInfo.size.split(";"))
						let heinumshow = this.ifnumshow(heiValue, goodsInfo.size.split(";"))
						if (weinumshow && heinumshow) { //如果两個都没有超过的话就正常判断
							if (Number(weiValue) > Number(heiValue)) {
								weiValue = this.MaxFn(weiValue, goodsInfo.size.split(";"))
							} else {
								heiValue = this.MaxFn(heiValue, goodsInfo.size.split(";"))
							}

						}
						if (weinumshow && !heinumshow) { //如果宽度没有超过高度超过了就計算宽度的值
							weiValue = this.MaxFn(weiValue, goodsInfo.size.split(";"))
							console.log(1);
						}
						if (!weinumshow && heinumshow) { //如果高度没有超过宽度超过了就計算高度的值
							heiValue = this.MaxFn(heiValue, goodsInfo.size.split(";"))
							console.log(2);
						}
					}
					value = eval((weiValue + info.wei_c + heiValue) + info.hei_c + info.numval)
				} else if (info.type == 2) {
					heiValue = eval(this.hei + info.hei_a + info.hei_b)
					value = eval(heiValue + info.hei_c + info.numval)
				} else if (info.type == 3) {
					value = Number(this.wei) > Number(this.hei) ? this.wei : this.hei
				} else if (info.type == 4) {
					value = Number(this.wei) > Number(this.hei) ? this.hei : this.wei
				} else if (info.type == 5) {
					weiValue = (Number(this.wei) / Number(info.wei_b)).toFixed(0) * Number(info.wei_b)
					heiValue = (Number(this.hei) / Number(info.hei_b)).toFixed(0) * Number(info.hei_b)
					value = eval(weiValue + info.wei_c + heiValue + info.hei_c + info.numval)
				}
				console.log(weiValue, "寬度", heiValue, "高度");
				this.formulaValue = (Number(value).toFixed(info.num))>=1?Number(value).toFixed(info.num):1
			},
			// reduceFn() {
			// 	this.num = Number(this.num) - 1
			// },
			// addFn() {
			// 	this.num = Number(this.num) + 1
			// },
			goSelectGoods(item) { //商品规格一選擇商品
				let arr = []
				item.shopclassify_id.split(",").forEach(value => {
					arr.push({
						id: value,
						name: ""
					})
				})
				item.shopclassify_name.split(",").forEach((value, index) => {
					arr[index].name = value
				})
				// uni.navigateTo({
				// 	url:"/pages/callOutOrder/classifyScreenGoods"
				// })
				uni.navigateTo({
					url: "/pages/callOutOrder/classifyScreenGoods?msg=" + encodeURIComponent(JSON.stringify(arr))
				})
			},
			async getList() { //選擇的二级商品
				let res = await this.http.request('/api/Ordergoods/deailOrdergoods', 'POST', {
					id: uni.getStorageSync("order_goods_id")
				})
				if (res.code == 1) {
					res.data.goods_data.forEach(item => {
						item.logoimage = this.imgUrlUser + item.logoimage
					})
					this.secondList = res.data.goods_data.filter(item => {
						return item.is_zhui == 1
					})
					// console.log(this.orderInfo);
				} else if (res.code == 0) {
					// this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			editGoods(item) { //编辑二级商品
				// uni.navigateTo({
				// 	url: "/pages_index/goodsInfoEdit?msg=" + encodeURIComponent(JSON.stringify(item))
				// })
				uni.navigateTo({
					url: "/pages_index/goodsInfoEditSecond?msg=" + encodeURIComponent(JSON.stringify(item))
				})
			},
			async removeOrder(id) { //刪除二级商品
				let res = await this.http.request('/api/ordergoods/delorderGoodslist', 'POST', {
					id
				})
				if (res.code == 1) {
					this.http.toast("刪除成功")
					let index = this.secondList.findIndex(item => {
						return id == item.id
					})
					this.secondList.splice(index, 1)
				} else if (res.code == 0) {
					this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			selectSpu(index, value, num_b) { //選擇商品规格二
				value.isChecked = value.isChecked ? false : true
				// if (num_b != 0) {
				// 	let selectNum = this.selectSpuNum[index].selectId.length
				// 	if (selectNum != num_b) {
				// 		this.selectSpuNum[index].selectId.push(value.id)
				// 		value.isChecked = true
				// 	} else {
				// 		let i = this.spuList[index].list.findIndex(item => {
				// 			return item.id == this.selectSpuNum[index].selectId[selectNum - 1]
				// 		})
				// 		this.spuList[index].list[i].isChecked = false
				// 		value.isChecked = true
				// 		this.$set(this.selectSpuNum[index].selectId, selectNum - 1, value.id)
				// 	}
				// } else {
				// 	this.spuList[index].list.forEach(item => {
				// 		item.isChecked = false
				// 	})
				// 	value.isChecked = true
				// }
			},
			confirm() {
				if (this.num > this.goodsInfo.xd_num && Number(this.goodsInfo.xd_num) != -1) {
					this.http.toast("當前商品限點" + this.goodsInfo.xd_num + "件")
					return false
				}
				if (this.goodsInfo.end_num != -1) {
					if (Number(this.num) > Number(this.goodsInfo.end_num)) {
						this.http.toast("當前商品庫存僅剩" + this.goodsInfo.end_num)
						return false
					}
				}
				if (this.goodsInfo.is_size == 1) {
					if (!this.wei) {
						this.http.toast("請輸入寬！")
						return false
					}
					if (!this.hei) {
						this.http.toast("請輸入高！")
						return false
					}
				}
				// if(this.sp_attr.length){
				// 	for (let i = 0; i < this.sp_attr.length; i++) {
				// 		let item = this.sp_attr[i]
				// 		if(item.value==""){
				// 			this.http.toast("請輸入"+item.name)
				// 			return false
				// 		}
				// 	}
				// }
				this.getAddOrderGoods()
			},
			async getAddOrderGoods() {
				let spunatdata = []
				for (let i = 0; i < this.spuList.length; i++) {
					let item = this.spuList[i]
					let num = 0
					item.list.forEach(value => {
						if (value.num != -0) {
							num = num + Number(value.num)
							spunatdata.push({
								spunatid: value.id,
								spunatname: value.name,
								num: value.num
							})
						}
					})
					if (item.fh == 1) { //等於
						if (num != item.num_b) {
							this.http.toast(item.name + "的規格選擇" + item.num_b + "個")
							return false
						}
					}
					if (item.fh == 2) { //大於等於
						if (num < item.num_b) {
							this.http.toast(item.name + "的規格至少選擇" + item.num_b + "個")
							return false
						}
					}
				}
				let data = {
					order_goods_id: uni.getStorageSync("order_goods_id"),
					shop_id: this.shop_id, //店鋪id
					goods_id: this.goods_id, //商品id
					goods_name: this.goodsInfo.name, //商品名称
					// goods_name: "哈哈哈", //商品名称
					logoimage: this.goodsInfo.logoimage, //商品logo
					wei: this.wei, //宽
					hei: this.hei, //高
					sp_attr: this.sp_attr,
					size: this.goodsInfo.unit, //單位
					spunatdata: spunatdata, //規格2
					num: this.num, //数量
					price: this.money, //价格
					d_price: this.djprice,
					addimage: this.addimage.join(), //上传的图片
					formulacount: this.formulaValue, //公式計算的值
					salename: this.goodsInfo.goods_sale.length ? this.goodsInfo.goods_sale[this.is_df].name :
					"", //销售类别名称
					type: 0, //0主商品 1子商品
				}
				if (this.posdc == 1) {
					this.$set(data, "is_zhui", 0)
				}
				let res = await this.http.request('/api/ordergoods/addorderGoodslist', 'POST', data)
				if (res.code == 1) {
					// uni.navigateBack({
					// 	delta: 1
					// })
					// this.getAddOrder(res.data)
					this.$emit('submitgoods', "")
				} else if (res.code == 0) {
					this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			async getAddOrder(id) {
				let res = await this.http.request('/api/goods/addorder', 'POST', {
					shop_id: this.shop_id, //店鋪id
					goods_ordergoodid: id, //订單id
					notes: this.notes, //商品名称
					money: this.money, //价格
				})
				if (res.code == 1) {
					uni.navigateTo({
						url: "./orderInfo"
					})
				} else if (res.code == 0) {
					this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.mainpaddingpos {
		padding: 6rpx;
	}

	// .itembox {
	// 	width: 33.33%;
	// }

	.itemboxcenter {
		background-color: #d3e3fd;
		padding: 20rpx 20rpx 0;
		border-radius: 20rpx;
	}

	.listbtn {
		padding: 10rpx 30rpx;
		border-radius: 50rpx;
		background-color: #ffb800;

	}

	.indicator {
		@include flex(row);
		justify-content: center;

		&__dot {
			height: 6px;
			width: 6px;
			border-radius: 100px;
			background-color: rgba(255, 255, 255, 0.35);
			margin: 0 5px;
			transition: background-color 0.3s;

			&--active {
				background-color: #ffffff;
			}
		}
	}

	.indicator-num {
		padding: 2px 0;
		background-color: rgba(0, 0, 0, 0.35);
		border-radius: 100px;
		width: 35px;
		@include flex;
		justify-content: center;

		&__text {
			color: #FFFFFF;
			font-size: 12px;
		}
	}

	.numberBg {
		background: #F7F7F7;
		padding: 8rpx 6rpx;
		border-radius: 10rpx 10rpx 10rpx 10rpx;
	}

	// .checkbox {
	// 	width: 30rpx;
	// 	height: 30rpx;
	// 	background-image: url("@/static/images/index/trueSelect.png");
	// 	background-size: 100% 100%;
	// }

	// .nocheckbox {
	// 	width: 30rpx;
	// 	height: 30rpx;
	// 	background-image: url("@/static/images/index/trueNoSelect.png");
	// 	background-size: 100% 100%;
	// }

	::v-deep .u-number-box__minus {
		background-color: #EC7AA0 !important;
	}

	::v-deep .u-number-box__plus {
		background-color: #EC7AA0 !important;
	}

	::v-deep .uicon-minus {
		color: #fff !important;
	}

	::v-deep .uicon-plus {
		color: #fff !important;
	}

	::v-deep.u-radio-group {
		flex: none !important;
	}

	.mainpadding {
		padding: 30rpx;
		box-sizing: border-box;
	}

	.mainpadding2 {
		padding: 0 30rpx 30rpx;
		box-sizing: border-box;
	}

	.mainpadding_top {
		padding: 30rpx;
		margin-top: 30rpx;
		box-sizing: border-box;
	}

	.margin_top {
		margin-top: 30rpx;
	}

	.margin_right2 {
		margin-right: 20rpx;
	}

	.margin_right {
		margin-right: 30rpx;
	}

	.margin_left2 {
		margin-left: 20rpx;
	}

	.margin_left {
		margin-left: 30rpx;
	}

	.flexcenter {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.flexbetween {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.flexleft {
		display: flex;
		align-items: center;
	}

	.flexright {
		display: flex;
		align-items: center;
		justify-content: flex-end;
	}

	.flex_wrap {
		flex-wrap: wrap;
	}

	.ffffff {
		background-color: #fff;
	}

	.radius {
		border-radius: 10rpx;
	}

	.xiaohui {
		font-size: 24rpx;
		color: #999;
	}

	.xiaohong {
		font-size: 34rpx;
		color: #ff0000;
	}

	.xiaohuang {
		font-size: 24rpx;
		color: #FF5C00;
	}

	.hui_text {
		color: #999;
	}

	.huang_text {
		color: #FF5C00;
	}

	.hei_text {
		color: #333;
	}

	.titletext {
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
	}

	.bold {
		font-weight: bold;
	}

	.main_size {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
	}

	.listleftimg {
		width: 150rpx;
		height: 150rpx;
		position: relative;
	}

	.pdl {
		padding-bottom: 30rpx;
		border-bottom: 1rpx dashed rgba(0, 0, 0, 1);
	}

	.listbtnhuang {
		border-radius: 50rpx;
		padding: 5rpx 15rpx;
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FF5C00;
		border: 1rpx solid #FF5C00;
	}

	.lableradius {
		border-radius: 10rpx 10rpx 10rpx 0;
		padding: 5rpx 10rpx;
		font-size: 26rpx,
	}

	.neiyong {
		background-color: #fff3e6;
		color: #ffb800;
	}

	/* //合計 */
	.posibottom {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		box-sizing: border-box;
	}

	.leftAllprice {
		padding: 30rpx 10rpx 30rpx 0rpx;
		border-radius: 50rpx 0 0 50rpx;
		flex: 6;
	}

	.rightsubmit {
		background-color: #ffb800;
		border-radius: 0 50rpx 50rpx 0;
		flex: 1;
	}

	.fuwulable {
		position: absolute;
		top: 0;
		right: 0;
		border-radius: 0 10rpx 0 10rpx;
		background-color: #fff4e8;
		font-size: 16rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #ffb800;
		padding: 5rpx 30rpx;
	}

	.bghui {
		background-color: #f7f7f6;
	}

	.bghuider {
		border: 1rpx solid #333;
	}

	.listleftimg2 {
		width: 110rpx;
		height: 110rpx;
	}

	.guigelable {
		background-color: #ffb800;
		color: #fff;
		font-size: 32rpx;
		padding: 15rpx 30rpx;
	}
</style>